<template>
  <view
    class="content ba_img"
    :style="{
      'padding-top': height + 'px',
    }"
  >
    <view
      :style="{
        height: statusBarHeight + 'px',
      }"
    >
    </view>
    <view
      class="head"
      :style="{
        top: statusBarHeight + 'px',
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#eeeeee"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text">今日更新</view>
    </view>

    <view class="tabs_box">
      <u-tabs
        class="tabs"
        :list="list1"
        @click="tabClick"
        :activeStyle="{
          color: '#eee',
          fontWeight: 'bold',
          transform: 'scale(1.05)',
          'font-size': '32rpx',
          paddingLeft: '12rpx',
          paddingRight: '12rpx',
        }"
        lineColor="#eee"
        :inactiveStyle="{
          color: '#ADADAD',
          transform: 'scale(1)',
          'font-size': '32rpx',
          paddingLeft: '12rpx',
          paddingRight: '12rpx',
        }"
        lineWidth="72rpx"
        :scrollable="false"
      ></u-tabs>
    </view>

    <scroll-view
      :style="{
        height: scrollHeihgt + 'px',
      }"
      :scroll-y="true"
      @scroll="scroll"
      @scrolltolower="scrolltolower"
    >
      <update-item :list="list" :my_level_id="my_level_id" :tab_id="tab_id"></update-item>
      <view class="" style="width: 100%; height: 80rpx"> </view>
    </scroll-view>

    <floatingBall></floatingBall>
  </view>
</template>

<script>
import updateItem from "./components/updateToday.vue";
export default {
  components: {
    updateItem,
  },
  props: {
    // list: {
    //   type: Object,
    //   default: () => {},
    // },
  },
  data() {
    return {
      statusBarHeight: 0,
      height: 0,
      scrollHeihgt: 0,
      list1: [
        {
          name: "平台",
        },
        {
          name: "导航者",
        },
        {
          name: "会员用户",
        },
      ],
      tab_id:1,
      list: [],
      page: 1,
      last_page: 0,
      my_level_id:0,
    };
  },
  created() {
    const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
    this.statusBarHeight = statusBarHeight.statusBarHeight;
    const windowHeihgt = statusBarHeight.windowHeight;
    this.$nextTick(() => {
      uni
        .createSelectorQuery()
        .select(".head")
        .boundingClientRect((data) => {
          this.height = data.height;
        })
        .exec();
    });

    this.$nextTick(() => {
      const query = uni.createSelectorQuery().in(this);
      query.select(".head").fields({
        size: true,
      });
      query.select(".tabs_box").fields({
        size: true,
      });

      query.exec((data) => {
        let sum = 0;
        data.forEach((item) => {
          sum += item.height;
        });
        this.scrollHeihgt = windowHeihgt - sum;
      });
    });
    this.getList(1);
  },
  methods: {
    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    scroll() {},
    scrolltolower() {
      if (this.page == this.last_page || this.last_page == 0) {
      } else {
        this.page++;
        this.getList(this.tab_id);
      }
      console.log("触发");
      console.log(this.page);
      console.log(this.last_page);
    },
    tabClick(e) {
      this.page = 1;
      this.last_page = 0;
      this.list = []
      this.tab_id = e.index + 1
      console.log("eee", e);
      this.getList(this.tab_id);
    },
    getList(tab_id) {
      this.$http
        .pageJinri({ tab_id: tab_id, page: this.page })
        .then((res) => {
          console.log(res.data.list.data, "今日更新");
          this.list = this.list.concat(res.data.list.data);
          this.last_page = res.data.list.last_page
          this.my_level_id = res.data.my_level_id
          // this.tab_id = res.data.tab_id
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
  },
};
</script>

<style scoped lang="scss">
.ba_img {
  width: 100%;
  height: 100%;
  position: fixed;
  margin: 0;
  background: url("/static/images/index.png") no-repeat;
  background-size: 100% 100%;
  background-attachment: fixed;
  box-sizing: border-box;
}

.head {
  width: 100%;
  padding: 18rpx 0 47rpx;
  position: fixed;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 99;

  .head_left {
    position: absolute;
    left: 30rpx;
  }

  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #eeeeee;
  }
}
</style>